package com.example.springfeature.postProcessor;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * Created with IDEA
 *
 * @author: 董文辉
 * Date: 2019/2/21
 * Time: 15:55
 */
@Component
public class UserProcessor implements BeanPostProcessor {
    @Nullable
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof User){
            System.out.println("正在前置处理器中准备初始化user");
        }
        return bean;
    }

    @Nullable
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof User){
            User user = (User) bean;
            user.setName("john");
            user.setPhone("13566655584");
            return user;
        }
        return bean;
    }
}
